﻿package fwk.siteManager {	

	import flash.display.MovieClip;
	import flash.events.Event;
	import fl.transitions.Tween;
	import fl.transitions.easing.None;
	import fl.transitions.TweenEvent;
	import fwk.siteManager.interfaces.IDisplayElement;
	import fwk.siteManager.events.ContainerLoaderEvent;
	import fwk.siteManager.events.TemplateEvent;
	import fwk.siteManager.interfaces.ITemplate;
	
//	import fwk.interfaces.IPage;
	
	public class DisplayElement extends MovieClip implements IDisplayElement
	{
		
		///////////////////////////
		// private properties
		private var _uiElement:String 		= "";
		private var _xmlConfig:XML;
		private var _xmlContent:XML;
		private var _transition:Tween;
		
		private var _template:ITemplate;


		public function get uiElement():String
		{
			return _uiElement;
		}
		public function get xmlConfig():XML
		{
			return _xmlConfig;
		}
		public function get xmlContent():XML
		{
			return _xmlContent;
		}
		
		public function get template():ITemplate { return _template; }
		
		public function set template(value:ITemplate):void 
		{
			_template = value;
		}
		
		
		//-----------------------------------------------------------------------
		// Constructeur
		//-----------------------------------------------------------------------
		function DisplayElement ():void
		{

			
		}
		
		//-----------------------------------------------------------------------
		// Methodes
		//-----------------------------------------------------------------------
		public final function _init(ui:String, xmlConfig:XML, xmlContent:XML = null):void
		{	
			_uiElement		= ui;
			_xmlConfig		= xmlConfig;
			_xmlContent		= xmlContent;
			

			
		}

		public function init():void
		{

		}
		
		public function display():void
		{
			trace("---------- display Element ----------");
			this.alpha = 0;
			if(_transition != null) _transition.stop();
			_transition = new Tween(this, "alpha" , None.easeNone, this.alpha, 1, 30, false);
		}
		public function close():void
		{
			trace("---------- close Element ----------");
			
			if (_transition != null) _transition.stop();
			_transition = new Tween(this, "alpha" , None.easeNone, this.alpha, 0, 20, false);
			_transition.addEventListener(TweenEvent.MOTION_FINISH, onCloseTweenFinish);
		}
		
		private function onCloseTweenFinish(evt:TweenEvent):void
		{
			_transition.removeEventListener(TweenEvent.MOTION_FINISH, onCloseFinish);
			onCloseFinish();
		}
		
		public function onCloseFinish():void
		{
			trace("---------- onCloseFinish Element ----------");
			
			dispatchEvent(new TemplateEvent(TemplateEvent.CLOSED));
			
		}
		public function dispose()
		{			
			
		}

		public function onDeepLinkChange():void
		{
				
			
		}
	}
}